import {ref} from 'vue'
import {http} from '@/axios'

export function useApi(api) {
  const loading = ref(false)
  let result = ref(null)
  const request = () => {
    loading.value = true
    return http.request(api).then(res => {
      result.value = res
    }).finally(() => {
      loading.value = false
    })
  }
  return {
    loading,
    result,
    request
  }
}
